<script>
	/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import appUpdate from '@/uni_modules/leruge-app-update/js_sdk/leruge-app-update.js'
	export default {
		onLaunch: function() {
			let userInfo = uni.getStorageSync('userInfo') || '';
			if (userInfo.uid > 0) {
				//更新登陆状态
				uni.getStorage({
					key: 'userInfo',
					success: (res) => {
						console.log('login')
						this.login(res.data);
					}
				});
			}

		},

		onShow: function() {
			// console.log('App Show')
			// #ifdef APP-PLUS
			this.updateVersion()
			// #endif
		},
		onHide: function() {
			// console.log('App Hide')
		},

		methods: {
			...mapMutations(['login', 'logout']),
			async updateVersion() {
				const systemInfo = uni.getSystemInfoSync()
				console.log(systemInfo.platform)
				if (systemInfo.platform === 'android') {
					let version = systemInfo.appWgtVersion;
					let cversion = parseInt(version.split(".").join(""));
					console.log(version);
					console.log(cversion);

					let res = await this.$myRequest({
						url: '/getSoftVersion',
						data: {
							field: 'zhgx_app_version'
						}
					})
					console.log(res.data);
					if (res.data.status == 1) {
						let sversion = parseInt(res.data.data.split(".").join(""))
						console.log(sversion)
						console.log(cversion < sversion)
						if (cversion < sversion) {
							let updateInfo = {
								platform: 'android',
								updateContent: '新版本强制更新',
								downUrl: 'https://zhgxapp.hnliandesy.com/download/zhgx.apk',
								version: res.data.value,
								force: true,
								mainColor: '0c80fb',
							}
							appUpdate(updateInfo)
						}

					}
				};
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "/common/zcm-main.css";
	@import "@/uni_modules/uview-ui/index.scss";

	page {
		font-size: 28rpx;
	}
</style>